//
//  ZHHeaderFooterCollectionView.m
//  sc-cyan-ios
//
//  Created by lj on 2017/12/28.
//  Copyright © 2017年 greenbuilding. All rights reserved.
//

#import "ZHHeaderFooterCollectionView.h"

@implementation ZHHeaderFooterCollectionView

- (void)setCollectionHeaderView:(UIView *)collectionHeaderView{
    
    _collectionHeaderView = collectionHeaderView;
    
    UIEdgeInsets inset = self.contentInset;
    
    CGFloat x = collectionHeaderView.origin.x;
    CGFloat lastY = collectionHeaderView.origin.y;
    CGFloat w = collectionHeaderView.size.width;
    CGFloat h = collectionHeaderView.size.height;
    CGFloat y = -h;
    collectionHeaderView.frame = CGRectMake(x, y, w, h);
    
    [self addSubview:collectionHeaderView];
    
    CGFloat ofsetY = lastY + h;
    
    self.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    
    self.contentInset = UIEdgeInsetsMake(ofsetY + inset.top, inset.left, inset.bottom, inset.right);
    
}

- (void)setCollectionFooterView:(UIView *)collectionFooterView{
    
    _collectionFooterView = collectionFooterView;
    
    UIEdgeInsets inset = self.contentInset;
    
    CGFloat x = collectionFooterView.origin.x;
    CGFloat lastY = collectionFooterView.origin.y;
    CGFloat w = collectionFooterView.size.width;
    CGFloat h = collectionFooterView.size.height;
    
    [self layoutIfNeeded];
    CGFloat y = self.contentSize.height + lastY;
    
    collectionFooterView.frame = CGRectMake(x, y, w, h);
    
    [self addSubview:collectionFooterView];
    
    CGFloat ofsetY = lastY + h;
    
    self.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    
    self.contentInset = UIEdgeInsetsMake(inset.top, inset.left,ofsetY + inset.bottom, inset.right);
    
}

@end
